#include "cledMatrixAngle.h"
#include <stdio.h>
#include <math.h>

#if 0
static const uint16_t RotateMatrixAngleLimit[MATRIX_ANGLE_SIZE][MATRIX_ANGLE_SIZE] = {
{0x0000, 0x0800, 0x1000, 0x1800, 0x2000, 0x2800, 0x3000, 0x3800, 0x4000, 0x4800, 0x5000, 0x5800, 0x6000, 0x6800, 0x7000, 0x7800, 0x8000, 0x8800, 0x9000, 0x9800, 0xA000, 0xA800, 0xB000, 0xB800, 0xC000, 0xC800, 0xD000, 0xD800, 0xE000, 0xE800, 0xF000, 0xF800, 0x0000, 0x0800, 0x1000, 0x1800, 0x2000, 0x2800, 0x3000, 0x3800, 0x4000, 0x4800, },
{0x0ACF, 0x0967, 0x10D4, 0x1893, 0x2070, 0x285A, 0x304B, 0x3841, 0x4039, 0x4832, 0x502D, 0x5829, 0x6026, 0x6823, 0x7020, 0x781E, 0x801C, 0x881A, 0x9019, 0x9818, 0xA016, 0xA815, 0xB014, 0xB813, 0xC013, 0xC812, 0xD011, 0xD810, 0xE010, 0xE80F, 0xF00F, 0xF80E, 0x000E, 0x080D, 0x100D, 0x180D, 0x200C, 0x280C, 0x300C, 0x380B, 0x400B, 0x480B, },
{0x12CF, 0x11FB, 0x1567, 0x1D0D, 0x20D4, 0x28AE, 0x3093, 0x387F, 0x4070, 0x4864, 0x505A, 0x5852, 0x604B, 0x6845, 0x7041, 0x783C, 0x8039, 0x8835, 0x9032, 0x9830, 0xA02D, 0xA82B, 0xB029, 0xB827, 0xC026, 0xC824, 0xD023, 0xD821, 0xE020, 0xE81F, 0xF01E, 0xF81D, 0x001C, 0x081B, 0x101A, 0x181A, 0x2019, 0x2818, 0x3018, 0x3817, 0x4016, 0x4816, },
{0x1ACF, 0x1A3C, 0x1DC2, 0x2167, 0x2926, 0x2CF7, 0x34D4, 0x3CB9, 0x44A4, 0x4893, 0x5085, 0x587A, 0x6070, 0x6867, 0x7060, 0x785A, 0x8054, 0x8850, 0x904B, 0x9847, 0xA044, 0xA841, 0xB03E, 0xB83B, 0xC039, 0xC836, 0xD034, 0xD832, 0xE030, 0xE82F, 0xF02D, 0xF82C, 0x002A, 0x0829, 0x1028, 0x1827, 0x2026, 0x2825, 0x3024, 0x3823, 0x4022, 0x4821, },
{0x22CF, 0x225F, 0x21FB, 0x29A9, 0x2D67, 0x3135, 0x390D, 0x40ED, 0x44D4, 0x4CBF, 0x54AE, 0x5C9F, 0x6493, 0x6C88, 0x747F, 0x7C77, 0x8070, 0x8869, 0x9064, 0x985F, 0xA05A, 0xA856, 0xB052, 0xB84E, 0xC04B, 0xC848, 0xD045, 0xD843, 0xE041, 0xE83E, 0xF03C, 0xF83A, 0x0039, 0x0837, 0x1035, 0x1834, 0x2032, 0x2831, 0x3030, 0x382E, 0x402D, 0x482C, },
{0x2ACF, 0x2A75, 0x2A21, 0x2DD8, 0x319A, 0x3967, 0x3D3E, 0x451C, 0x4900, 0x50E8, 0x58D4, 0x60C3, 0x68B4, 0x6CA8, 0x749D, 0x7C93, 0x848A, 0x8C83, 0x947C, 0x9C75, 0xA470, 0xAC6B, 0xB466, 0xBC62, 0xC45E, 0xC85A, 0xD057, 0xD853, 0xE050, 0xE84E, 0xF04B, 0xF849, 0x0047, 0x0844, 0x1042, 0x1841, 0x203F, 0x283D, 0x303B, 0x383A, 0x4039, 0x4837, },
{0x32CF, 0x3284, 0x323C, 0x35FB, 0x39C2, 0x3D91, 0x4167, 0x4944, 0x5126, 0x550D, 0x5CF7, 0x64E4, 0x68D4, 0x70C6, 0x78B9, 0x80AE, 0x88A4, 0x909B, 0x9493, 0x9C8C, 0xA485, 0xAC7F, 0xB47A, 0xBC74, 0xC470, 0xCC6B, 0xD467, 0xDC64, 0xE460, 0xEC5D, 0xF45A, 0xFC57, 0x0454, 0x0C52, 0x1450, 0x1C4D, 0x204B, 0x2849, 0x3047, 0x3845, 0x4044, 0x4842, },
{0x3ACF, 0x3A8E, 0x3A50, 0x3E16, 0x41E2, 0x45B3, 0x498B, 0x4D67, 0x5549, 0x592E, 0x6117, 0x6903, 0x6CF2, 0x74E2, 0x7CD4, 0x84C8, 0x88BD, 0x90B3, 0x98AA, 0xA0A1, 0xA89A, 0xB093, 0xB88D, 0xC087, 0xC882, 0xCC7D, 0xD478, 0xDC74, 0xE470, 0xEC6C, 0xF469, 0xFC65, 0x0462, 0x0C5F, 0x145D, 0x1C5A, 0x2458, 0x2C55, 0x3453, 0x3C51, 0x444F, 0x4C4D, },
{0x42CF, 0x4296, 0x425F, 0x462B, 0x45FB, 0x49CF, 0x51A9, 0x5586, 0x5967, 0x614D, 0x6535, 0x6D20, 0x710D, 0x78FC, 0x80ED, 0x88E0, 0x8CD4, 0x94C9, 0x9CBF, 0xA4B6, 0xACAE, 0xB0A6, 0xB89F, 0xC099, 0xC893, 0xD08D, 0xD888, 0xE084, 0xE87F, 0xF07B, 0xF877, 0x0073, 0x0470, 0x0C6D, 0x1469, 0x1C67, 0x2464, 0x2C61, 0x345F, 0x3C5C, 0x445A, 0x4C58, },
{0x4ACF, 0x4A9D, 0x4A6B, 0x4A3C, 0x4E10, 0x51E7, 0x55C2, 0x59A1, 0x6182, 0x6567, 0x694F, 0x713A, 0x7926, 0x7D15, 0x8505, 0x88F7, 0x90EA, 0x98DF, 0xA0D4, 0xA8CA, 0xACC1, 0xB4B9, 0xBCB1, 0xC4AA, 0xCCA4, 0xD49E, 0xDC98, 0xE093, 0xE88E, 0xF089, 0xF885, 0x0081, 0x087D, 0x107A, 0x1876, 0x2073, 0x2870, 0x306D, 0x386A, 0x4067, 0x4865, 0x4C63, },
{0x52CF, 0x52A2, 0x5275, 0x524A, 0x5621, 0x59FB, 0x5DD8, 0x61B8, 0x659A, 0x6980, 0x7167, 0x7552, 0x7D3E, 0x812C, 0x891C, 0x910D, 0x9500, 0x9CF3, 0xA4E8, 0xA8DE, 0xB0D4, 0xB8CB, 0xC0C3, 0xC8BB, 0xD0B4, 0xD4AE, 0xDCA8, 0xE4A2, 0xEC9D, 0xF498, 0xFC93, 0x048F, 0x0C8A, 0x1086, 0x1883, 0x207F, 0x287C, 0x3078, 0x3875, 0x4073, 0x4870, 0x506D, },
{0x5ACF, 0x5AA6, 0x5A7D, 0x5A55, 0x5E30, 0x620C, 0x65EB, 0x69CC, 0x6DAF, 0x7195, 0x757D, 0x7D67, 0x8154, 0x8941, 0x8D31, 0x9522, 0x9914, 0xA107, 0xA8FB, 0xACF0, 0xB4E6, 0xBCDD, 0xC4D4, 0xC8CC, 0xD0C4, 0xD8BD, 0xE0B7, 0xE8B1, 0xF0AB, 0xF8A6, 0xFCA1, 0x049C, 0x0C97, 0x1493, 0x1C8F, 0x248B, 0x2C87, 0x3484, 0x3C81, 0x447E, 0x487B, 0x5078, },
{0x62CF, 0x62A9, 0x6284, 0x625F, 0x663C, 0x6A1B, 0x69FB, 0x6DDD, 0x71C2, 0x79A9, 0x7D91, 0x817B, 0x8567, 0x8D55, 0x9144, 0x9935, 0xA126, 0xA519, 0xAD0D, 0xB102, 0xB8F7, 0xC0ED, 0xC8E4, 0xCCDC, 0xD4D4, 0xDCCD, 0xE4C6, 0xECBF, 0xF0B9, 0xF8B3, 0x00AE, 0x08A9, 0x10A4, 0x189F, 0x209B, 0x2897, 0x2C93, 0x348F, 0x3C8C, 0x4488, 0x4C85, 0x5482, },
{0x6ACF, 0x6AAC, 0x6A8A, 0x6A68, 0x6E47, 0x6E27, 0x7209, 0x75ED, 0x79D3, 0x7DBA, 0x81A3, 0x898E, 0x8D7A, 0x9167, 0x9957, 0x9D47, 0xA538, 0xA92B, 0xB11E, 0xB913, 0xBD08, 0xC4FE, 0xCCF4, 0xD0EB, 0xD8E3, 0xE0DB, 0xE8D4, 0xECCD, 0xF4C7, 0xFCC1, 0x04BB, 0x0CB6, 0x14B0, 0x18AC, 0x20A7, 0x28A3, 0x309E, 0x389A, 0x4097, 0x4893, 0x5090, 0x588C, },
{0x72CF, 0x72AF, 0x728E, 0x726F, 0x7650, 0x7632, 0x7A16, 0x7DFB, 0x81E2, 0x85CA, 0x89B3, 0x8D9E, 0x918B, 0x9978, 0x9D67, 0xA558, 0xA949, 0xB13B, 0xB52E, 0xBD23, 0xC117, 0xC90D, 0xD103, 0xD4FA, 0xDCF2, 0xE4E9, 0xECE2, 0xF0DB, 0xF8D4, 0x00CE, 0x08C8, 0x10C2, 0x14BD, 0x1CB7, 0x24B3, 0x2CAE, 0x34AA, 0x3CA5, 0x40A1, 0x489D, 0x509A, 0x5896, },
{0x7ACF, 0x7AB1, 0x7A93, 0x7A75, 0x7E58, 0x7E3C, 0x8221, 0x8607, 0x89EF, 0x89D8, 0x91C2, 0x95AD, 0x999A, 0x9D88, 0xA577, 0xA967, 0xAD59, 0xB54B, 0xB93E, 0xC132, 0xC926, 0xCD1C, 0xD512, 0xD908, 0xE100, 0xE8F7, 0xF0EF, 0xF4E8, 0xFCE1, 0x04DA, 0x0CD4, 0x10CE, 0x18C8, 0x20C3, 0x28BE, 0x30B9, 0x38B4, 0x3CB0, 0x44AC, 0x4CA8, 0x54A4, 0x5CA0, },
{0x82CF, 0x82B3, 0x8296, 0x827B, 0x825F, 0x8645, 0x8A2B, 0x8A12, 0x8DFB, 0x91E5, 0x95CF, 0x99BB, 0xA1A9, 0xA597, 0xA986, 0xAD76, 0xB567, 0xB95A, 0xC14D, 0xC540, 0xCD35, 0xD12A, 0xD920, 0xE116, 0xE50D, 0xED04, 0xF4FC, 0xF8F5, 0x00ED, 0x08E7, 0x10E0, 0x14DA, 0x1CD4, 0x24CE, 0x2CC9, 0x30C4, 0x38BF, 0x40BB, 0x48B6, 0x50B2, 0x58AE, 0x60AA, },
{0x8ACF, 0x8AB5, 0x8A9A, 0x8A7F, 0x8A66, 0x8E4C, 0x9234, 0x921C, 0x9606, 0x99F0, 0x9DDC, 0xA1C8, 0xA5B6, 0xA9A4, 0xB194, 0xB584, 0xB975, 0xC167, 0xC55A, 0xC94E, 0xD142, 0xD937, 0xDD2D, 0xE523, 0xE91A, 0xF111, 0xF909, 0xFD01, 0x04FA, 0x0CF3, 0x10EC, 0x18E5, 0x20DF, 0x28DA, 0x30D4, 0x34CF, 0x3CCA, 0x44C5, 0x4CC0, 0x54BC, 0x58B8, 0x60B4, },
{0x92CF, 0x92B6, 0x929D, 0x9284, 0x926B, 0x9653, 0x963C, 0x9A25, 0x9E10, 0xA1FB, 0xA5E7, 0xA9D4, 0xADC2, 0xB1B1, 0xB5A1, 0xB991, 0xC182, 0xC575, 0xC967, 0xD15B, 0xD54F, 0xDD44, 0xE13A, 0xE930, 0xF126, 0xF51E, 0xFD15, 0x010D, 0x0905, 0x10FE, 0x14F7, 0x1CF1, 0x24EA, 0x2CE4, 0x30DF, 0x38D9, 0x40D4, 0x48CF, 0x50CA, 0x54C6, 0x5CC1, 0x64BD, },
{0x9ACF, 0x9AB7, 0x9A9F, 0x9A88, 0x9A70, 0x9E5A, 0x9E43, 0xA22E, 0xA619, 0xAA05, 0xA9F1, 0xADDF, 0xB1CD, 0xB9BC, 0xBDAC, 0xC19D, 0xC58F, 0xC981, 0xD174, 0xD567, 0xDD5C, 0xE151, 0xE946, 0xED3C, 0xF532, 0xF929, 0x0121, 0x0919, 0x0D11, 0x1509, 0x1D02, 0x20FC, 0x28F5, 0x30EF, 0x34E9, 0x3CE3, 0x44DE, 0x4CD9, 0x50D4, 0x58CF, 0x60CB, 0x68C6, },
{0xA2CF, 0xA2B9, 0xA2A2, 0xA28B, 0xA275, 0xA65F, 0xA64A, 0xAA35, 0xAE21, 0xAE0E, 0xB1FB, 0xB5E9, 0xB9D8, 0xBDC7, 0xC1B8, 0xC9A9, 0xCD9A, 0xD18D, 0xD580, 0xDD73, 0xE167, 0xE95C, 0xED52, 0xF148, 0xF93E, 0x0135, 0x052C, 0x0D24, 0x111C, 0x1914, 0x210D, 0x2506, 0x2D00, 0x34F9, 0x38F3, 0x40ED, 0x48E8, 0x50E3, 0x54DE, 0x5CD9, 0x64D4, 0x6CD0, },
{0xAACF, 0xAABA, 0xAAA4, 0xAA8E, 0xAA79, 0xAE64, 0xAE50, 0xB23C, 0xB229, 0xB616, 0xBA04, 0xBDF2, 0xC1E2, 0xC5D1, 0xC9C2, 0xCDB3, 0xD1A5, 0xD998, 0xDD8B, 0xE17E, 0xE973, 0xED67, 0xF15D, 0xF953, 0xFD49, 0x0540, 0x0937, 0x112E, 0x1926, 0x1D1F, 0x2517, 0x2910, 0x310A, 0x3903, 0x3CFD, 0x44F7, 0x4CF2, 0x54EC, 0x58E7, 0x60E2, 0x68DD, 0x70D8, },
{0xB2CF, 0xB2BB, 0xB2A6, 0xB291, 0xB27D, 0xB669, 0xB655, 0xBA42, 0xBA30, 0xBE1E, 0xC20C, 0xC5FB, 0xC9EB, 0xCDDB, 0xD1CC, 0xD5BD, 0xD9AF, 0xDDA2, 0xE195, 0xE989, 0xED7D, 0xF172, 0xF967, 0xFD5D, 0x0554, 0x094A, 0x1141, 0x1539, 0x1D31, 0x2129, 0x2922, 0x311A, 0x3514, 0x3D0D, 0x4107, 0x4901, 0x50FB, 0x58F5, 0x5CF0, 0x64EB, 0x6CE6, 0x74E1, },
{0xBACF, 0xBABC, 0xBAA8, 0xBA94, 0xBA81, 0xBE6D, 0xBE5B, 0xC248, 0xC236, 0xC625, 0xCA14, 0xCA03, 0xCDF3, 0xD1E4, 0xD5D5, 0xD9C7, 0xE1B9, 0xE5AC, 0xE99F, 0xED93, 0xF187, 0xF97C, 0xFD72, 0x0567, 0x095E, 0x0D54, 0x154B, 0x1943, 0x213B, 0x2933, 0x2D2B, 0x3524, 0x391D, 0x4117, 0x4910, 0x4D0A, 0x5504, 0x5CFE, 0x60F9, 0x68F4, 0x70EF, 0x78EA, },
{0xC2CF, 0xC2BC, 0xC2A9, 0xC296, 0xC284, 0xC671, 0xC65F, 0xCA4D, 0xCA3C, 0xCE2B, 0xD21B, 0xD20B, 0xD5FB, 0xD9EC, 0xDDDD, 0xE1CF, 0xE5C2, 0xE9B5, 0xF1A9, 0xF59D, 0xF991, 0xFD86, 0x057B, 0x0971, 0x0D67, 0x155E, 0x1955, 0x214D, 0x2544, 0x2D3C, 0x3135, 0x392D, 0x4126, 0x4520, 0x4D19, 0x5113, 0x590D, 0x6107, 0x6502, 0x6CFC, 0x74F7, 0x7CF2, },
{0xCACF, 0xCABD, 0xCAAB, 0xCA99, 0xCA87, 0xCA75, 0xCE64, 0xCE52, 0xD242, 0xD631, 0xD621, 0xDA12, 0xDE02, 0xE1F4, 0xE5E6, 0xE9D8, 0xEDCB, 0xF1BE, 0xF5B1, 0xF9A6, 0x019A, 0x058F, 0x0985, 0x0D7B, 0x1571, 0x1967, 0x215F, 0x2556, 0x2D4E, 0x3146, 0x393E, 0x3D37, 0x452F, 0x4929, 0x5122, 0x591C, 0x5D16, 0x6510, 0x690A, 0x7105, 0x7900, 0x80FA, },
{0xD2CF, 0xD2BE, 0xD2AC, 0xD29B, 0xD28A, 0xD278, 0xD668, 0xD657, 0xDA47, 0xDE37, 0xDE27, 0xE218, 0xE609, 0xE9FB, 0xEDED, 0xF1E0, 0xF5D3, 0xF9C6, 0xFDBA, 0x01AE, 0x05A3, 0x0998, 0x118E, 0x1584, 0x197A, 0x2170, 0x2567, 0x295F, 0x3157, 0x354F, 0x3D47, 0x413F, 0x4938, 0x5131, 0x552B, 0x5D24, 0x611E, 0x6918, 0x7113, 0x750D, 0x7D08, 0x8503, },
{0xDACF, 0xDABF, 0xDAAE, 0xDA9D, 0xDA8C, 0xDA7C, 0xDE6B, 0xDE5B, 0xE24B, 0xE23C, 0xE62D, 0xEA1E, 0xEE10, 0xEE02, 0xF1F4, 0xF5E7, 0xF9DA, 0xFDCE, 0x01C2, 0x09B6, 0x0DAB, 0x11A1, 0x1596, 0x198C, 0x2182, 0x2579, 0x2970, 0x3167, 0x355F, 0x3D57, 0x414F, 0x4948, 0x4D41, 0x553A, 0x5933, 0x612D, 0x6926, 0x6D20, 0x751B, 0x7915, 0x8110, 0x890A, },
{0xE2CF, 0xE2BF, 0xE2AF, 0xE29F, 0xE28E, 0xE27F, 0xE66F, 0xE65F, 0xEA50, 0xEA41, 0xEE32, 0xF224, 0xF216, 0xF608, 0xF9FB, 0xFDEE, 0x01E2, 0x05D5, 0x09CA, 0x0DBE, 0x11B3, 0x19A9, 0x1D9E, 0x2194, 0x258B, 0x2D81, 0x3178, 0x3570, 0x3D67, 0x415F, 0x4958, 0x4D50, 0x5549, 0x5942, 0x613B, 0x6535, 0x6D2E, 0x7128, 0x7923, 0x811D, 0x8517, 0x8D12, },
{0xEACF, 0xEAC0, 0xEAB0, 0xEAA0, 0xEA91, 0xEA81, 0xEE72, 0xEE63, 0xF254, 0xF246, 0xF637, 0xFA29, 0xFA1C, 0xFE0E, 0x0201, 0x05F5, 0x09E8, 0x0DDC, 0x11D1, 0x15C6, 0x19BB, 0x1DB0, 0x21A6, 0x299C, 0x2D93, 0x3189, 0x3580, 0x3D78, 0x4170, 0x4967, 0x4D60, 0x5158, 0x5951, 0x5D4A, 0x6543, 0x693D, 0x7136, 0x7930, 0x7D2A, 0x8525, 0x891F, 0x911A, },
{0xF2CF, 0xF2C0, 0xF2B1, 0xF2A2, 0xF293, 0xF284, 0xF675, 0xF666, 0xFA58, 0xFA4A, 0xFE3C, 0xFE2E, 0x0221, 0x0614, 0x0A07, 0x0DFB, 0x11EF, 0x11E3, 0x15D8, 0x1DCD, 0x21C2, 0x25B8, 0x29AD, 0x2DA4, 0x319A, 0x3991, 0x3D88, 0x4180, 0x4977, 0x4D6F, 0x5167, 0x5960, 0x5D59, 0x6552, 0x694B, 0x7144, 0x753E, 0x7D38, 0x8132, 0x892C, 0x9126, 0x9521, },
{0xFACF, 0xFAC1, 0xFAB2, 0xFAA3, 0xFA95, 0xFA86, 0xFE78, 0xFE6A, 0x025C, 0x024E, 0x0640, 0x0633, 0x0A26, 0x0E19, 0x120D, 0x1201, 0x15F5, 0x19EA, 0x1DDE, 0x21D3, 0x25C9, 0x29BF, 0x31B5, 0x35AB, 0x39A2, 0x3D98, 0x4190, 0x4987, 0x4D7F, 0x5177, 0x596F, 0x5D67, 0x6560, 0x6959, 0x7152, 0x754C, 0x7D45, 0x813F, 0x8939, 0x8D33, 0x952E, 0x9928, },
{0x02CF, 0x02C1, 0x02B3, 0x02A5, 0x0296, 0x0288, 0x067B, 0x066D, 0x065F, 0x0A52, 0x0E45, 0x0E38, 0x122B, 0x161F, 0x1612, 0x1A07, 0x1DFB, 0x21F0, 0x25E5, 0x29DA, 0x2DCF, 0x31C5, 0x35BB, 0x39B2, 0x41A9, 0x45A0, 0x4997, 0x4D8E, 0x5586, 0x597E, 0x5D76, 0x656F, 0x6967, 0x6D60, 0x755A, 0x7953, 0x814D, 0x8546, 0x8D40, 0x913A, 0x9935, 0xA12F, },
{0x0ACF, 0x0AC2, 0x0AB4, 0x0AA6, 0x0A98, 0x0A8B, 0x0E7D, 0x0E70, 0x0E62, 0x1255, 0x1249, 0x163C, 0x1A30, 0x1A23, 0x1E18, 0x220C, 0x2601, 0x29F5, 0x2DEB, 0x31E0, 0x35D6, 0x39CC, 0x3DC2, 0x41B8, 0x45AF, 0x49A6, 0x519E, 0x5595, 0x598D, 0x5D85, 0x657D, 0x6976, 0x6D6F, 0x7567, 0x7961, 0x815A, 0x8554, 0x8D4D, 0x9147, 0x9941, 0x9D3C, 0xA536, },
{0x12CF, 0x12C2, 0x12B5, 0x12A7, 0x129A, 0x128D, 0x167F, 0x1672, 0x1666, 0x1A59, 0x1A4C, 0x1E40, 0x2234, 0x2228, 0x261C, 0x2A11, 0x2E06, 0x31FB, 0x31F0, 0x35E6, 0x39DC, 0x3DD2, 0x41C8, 0x49BF, 0x4DB6, 0x51AD, 0x55A4, 0x599C, 0x6194, 0x658C, 0x6984, 0x717D, 0x7575, 0x796E, 0x8167, 0x8561, 0x8D5A, 0x9154, 0x954E, 0x9D48, 0xA142, 0xA93D, },
{0x1ACF, 0x1AC2, 0x1AB5, 0x1AA8, 0x1A9B, 0x1A8E, 0x1E82, 0x1E75, 0x1E68, 0x225C, 0x2250, 0x2644, 0x2A38, 0x2A2C, 0x2E21, 0x3216, 0x320B, 0x3600, 0x39F6, 0x3DEC, 0x41E2, 0x45D8, 0x49CE, 0x4DC5, 0x51BC, 0x59B3, 0x5DAB, 0x61A2, 0x659A, 0x6992, 0x718B, 0x7583, 0x797C, 0x8175, 0x856E, 0x8967, 0x9161, 0x955B, 0x9D55, 0xA14F, 0xA949, 0xAD43, },
{0x22CF, 0x22C3, 0x22B6, 0x22A9, 0x229D, 0x2290, 0x2284, 0x2677, 0x266B, 0x2A5F, 0x2A53, 0x2E48, 0x2E3C, 0x3231, 0x3625, 0x3A1B, 0x3A10, 0x3E05, 0x41FB, 0x45F1, 0x49E7, 0x4DDD, 0x51D4, 0x55CB, 0x59C2, 0x5DB9, 0x61B1, 0x69A9, 0x6DA1, 0x7199, 0x7591, 0x7D8A, 0x8182, 0x857B, 0x8D75, 0x916E, 0x9567, 0x9D61, 0xA15B, 0xA955, 0xAD4F, 0xB54A, },
{0x2ACF, 0x2AC3, 0x2AB7, 0x2AAA, 0x2A9E, 0x2A92, 0x2A86, 0x2E7A, 0x2E6E, 0x3262, 0x3257, 0x364B, 0x3640, 0x3A35, 0x3E2A, 0x3E1F, 0x4214, 0x460A, 0x4A00, 0x4DF6, 0x51EC, 0x55E3, 0x59DA, 0x5DD1, 0x61C8, 0x65BF, 0x69B7, 0x6DAF, 0x71A7, 0x799F, 0x7D97, 0x8190, 0x8589, 0x8D82, 0x917B, 0x9574, 0x9D6E, 0xA167, 0xA961, 0xAD5B, 0xB156, 0xB950, },
{0x32CF, 0x32C3, 0x32B7, 0x32AB, 0x329F, 0x3294, 0x3288, 0x367C, 0x3670, 0x3A65, 0x3A5A, 0x3E4E, 0x3E43, 0x4238, 0x422E, 0x4623, 0x4A19, 0x4E0F, 0x5205, 0x51FB, 0x55F1, 0x59E8, 0x5DDF, 0x61D6, 0x65CD, 0x69C5, 0x71BC, 0x75B4, 0x79AC, 0x7DA5, 0x819D, 0x8996, 0x8D8F, 0x9188, 0x9581, 0x9D7A, 0xA174, 0xA96E, 0xAD67, 0xB162, 0xB95C, 0xBD56, },
{0x3ACF, 0x3AC4, 0x3AB8, 0x3AAC, 0x3AA1, 0x3A95, 0x3A8A, 0x3E7E, 0x3E73, 0x4268, 0x425C, 0x4651, 0x4647, 0x4A3C, 0x4A32, 0x4E27, 0x521D, 0x5613, 0x5609, 0x5A00, 0x5DF6, 0x61ED, 0x65E4, 0x69DB, 0x6DD3, 0x71CA, 0x75C2, 0x79BA, 0x81B2, 0x85AA, 0x89A3, 0x8D9C, 0x9195, 0x998E, 0x9D87, 0xA180, 0xA97A, 0xAD74, 0xB16D, 0xB967, 0xBD62, 0xC55C, },
{0x42CF, 0x42C4, 0x42B9, 0x42AD, 0x42A2, 0x4296, 0x428B, 0x4680, 0x4675, 0x4A6A, 0x4A5F, 0x4A54, 0x4E4A, 0x523F, 0x5235, 0x562B, 0x5A21, 0x5A17, 0x5E0E, 0x6204, 0x65FB, 0x69F2, 0x6DE9, 0x71E0, 0x75D8, 0x79CF, 0x7DC7, 0x81BF, 0x85B8, 0x89B0, 0x91A9, 0x95A1, 0x999A, 0x9D93, 0xA18D, 0xA986, 0xAD80, 0xB179, 0xB973, 0xBD6D, 0xC567, 0xC962, },
{0x4ACF, 0x4AC4, 0x4AB9, 0x4AAE, 0x4AA3, 0x4A98, 0x4A8D, 0x4E82, 0x4E77, 0x4E6C, 0x5262, 0x5257, 0x564D, 0x5A43, 0x5A39, 0x5E2F, 0x6225, 0x621B, 0x6612, 0x6A09, 0x6DFF, 0x71F7, 0x75EE, 0x79E5, 0x7DDD, 0x81D5, 0x85CC, 0x89C5, 0x8DBD, 0x91B5, 0x95AE, 0x99A7, 0xA1A0, 0xA599, 0xA992, 0xAD8C, 0xB585, 0xB97F, 0xBD79, 0xC573, 0xC96D, 0xCD67, },
};
#else
static const uint16_t RotateMatrixAngle[MATRIX_ANGLE_SIZE][MATRIX_ANGLE_SIZE] = {
{0x0000, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x2400, 0x2800, 0x2C00, 0x3000, 0x3400, 0x3800, 0x3C00, 0x4000, 0x4400, 0x4800, 0x4C00, 0x5000, 0x5400, 0x5800, 0x5C00, 0x6000, 0x6400, 0x6800, 0x6C00, 0x7000, 0x7400, 0x7800, 0x7C00, 0x8000, 0x8400, 0x8800, 0x8C00, 0x9000, 0x9400, 0x9800, 0x9C00, 0xA000, 0xA400, },
{0x06CF, 0x0567, 0x08D4, 0x0C93, 0x1070, 0x145A, 0x184B, 0x1C41, 0x2039, 0x2432, 0x282D, 0x2C29, 0x3026, 0x3423, 0x3820, 0x3C1E, 0x401C, 0x441A, 0x4819, 0x4C18, 0x5016, 0x5415, 0x5814, 0x5C13, 0x6013, 0x6412, 0x6811, 0x6C10, 0x7010, 0x740F, 0x780F, 0x7C0E, 0x800E, 0x840D, 0x880D, 0x8C0D, 0x900C, 0x940C, 0x980C, 0x9C0B, 0xA00B, 0xA40B, },
{0x0ACF, 0x09FB, 0x0967, 0x0D0D, 0x10D4, 0x14AE, 0x1893, 0x1C7F, 0x2070, 0x2464, 0x285A, 0x2C52, 0x304B, 0x3445, 0x3841, 0x3C3C, 0x4039, 0x4435, 0x4832, 0x4C30, 0x502D, 0x542B, 0x5829, 0x5C27, 0x6026, 0x6424, 0x6823, 0x6C21, 0x7020, 0x741F, 0x781E, 0x7C1D, 0x801C, 0x841B, 0x881A, 0x8C1A, 0x9019, 0x9418, 0x9818, 0x9C17, 0xA016, 0xA416, },
{0x0ECF, 0x0E3C, 0x0DC2, 0x1167, 0x1526, 0x14F7, 0x18D4, 0x1CB9, 0x20A4, 0x2493, 0x2885, 0x2C7A, 0x3070, 0x3467, 0x3860, 0x3C5A, 0x4054, 0x4450, 0x484B, 0x4C47, 0x5044, 0x5441, 0x583E, 0x5C3B, 0x6039, 0x6436, 0x6834, 0x6C32, 0x7030, 0x742F, 0x782D, 0x7C2C, 0x802A, 0x8429, 0x8828, 0x8C27, 0x9026, 0x9425, 0x9824, 0x9C23, 0xA022, 0xA421, },
{0x12CF, 0x125F, 0x11FB, 0x15A9, 0x1567, 0x1935, 0x1D0D, 0x20ED, 0x20D4, 0x24BF, 0x28AE, 0x2C9F, 0x3093, 0x3488, 0x387F, 0x3C77, 0x4070, 0x4469, 0x4864, 0x4C5F, 0x505A, 0x5456, 0x5852, 0x5C4E, 0x604B, 0x6448, 0x6845, 0x6C43, 0x7041, 0x743E, 0x783C, 0x7C3A, 0x8039, 0x8437, 0x8835, 0x8C34, 0x9032, 0x9431, 0x9830, 0x9C2E, 0xA02D, 0xA42C, },
{0x16CF, 0x1675, 0x1621, 0x15D8, 0x199A, 0x1D67, 0x1D3E, 0x211C, 0x2500, 0x28E8, 0x2CD4, 0x30C3, 0x34B4, 0x34A8, 0x389D, 0x3C93, 0x408A, 0x4483, 0x487C, 0x4C75, 0x5070, 0x546B, 0x5866, 0x5C62, 0x605E, 0x645A, 0x6857, 0x6C53, 0x7050, 0x744E, 0x784B, 0x7C49, 0x8047, 0x8444, 0x8842, 0x8C41, 0x903F, 0x943D, 0x983B, 0x9C3A, 0xA039, 0xA437, },
{0x1ACF, 0x1A84, 0x1A3C, 0x19FB, 0x1DC2, 0x1D91, 0x2167, 0x2544, 0x2926, 0x290D, 0x2CF7, 0x30E4, 0x34D4, 0x38C6, 0x3CB9, 0x40AE, 0x44A4, 0x489B, 0x4893, 0x4C8C, 0x5085, 0x547F, 0x587A, 0x5C74, 0x6070, 0x646B, 0x6867, 0x6C64, 0x7060, 0x745D, 0x785A, 0x7C57, 0x8054, 0x8452, 0x8850, 0x8C4D, 0x904B, 0x9449, 0x9847, 0x9C45, 0xA044, 0xA442, },
{0x1ECF, 0x1E8E, 0x1E50, 0x1E16, 0x21E2, 0x21B3, 0x258B, 0x2567, 0x2949, 0x2D2E, 0x3117, 0x3503, 0x34F2, 0x38E2, 0x3CD4, 0x40C8, 0x44BD, 0x48B3, 0x4CAA, 0x50A1, 0x549A, 0x5893, 0x5C8D, 0x6087, 0x6482, 0x647D, 0x6878, 0x6C74, 0x7070, 0x746C, 0x7869, 0x7C65, 0x8062, 0x845F, 0x885D, 0x8C5A, 0x9058, 0x9455, 0x9853, 0x9C51, 0xA04F, 0xA44D, },
{0x22CF, 0x2296, 0x225F, 0x222B, 0x21FB, 0x25CF, 0x29A9, 0x2986, 0x2D67, 0x314D, 0x3135, 0x3520, 0x390D, 0x3CFC, 0x40ED, 0x44E0, 0x44D4, 0x48C9, 0x4CBF, 0x50B6, 0x54AE, 0x58A6, 0x5C9F, 0x6099, 0x6493, 0x688D, 0x6C88, 0x7084, 0x747F, 0x787B, 0x7C77, 0x8073, 0x8070, 0x846D, 0x8869, 0x8C67, 0x9064, 0x9461, 0x985F, 0x9C5C, 0xA05A, 0xA458, },
{0x26CF, 0x269D, 0x266B, 0x263C, 0x2610, 0x29E7, 0x29C2, 0x2DA1, 0x3182, 0x3167, 0x354F, 0x393A, 0x3D26, 0x3D15, 0x4105, 0x44F7, 0x48EA, 0x4CDF, 0x50D4, 0x54CA, 0x54C1, 0x58B9, 0x5CB1, 0x60AA, 0x64A4, 0x689E, 0x6C98, 0x7093, 0x748E, 0x7889, 0x7C85, 0x8081, 0x847D, 0x887A, 0x8C76, 0x9073, 0x9470, 0x986D, 0x9C6A, 0xA067, 0xA465, 0xA463, },
{0x2ACF, 0x2AA2, 0x2A75, 0x2A4A, 0x2A21, 0x2DFB, 0x2DD8, 0x31B8, 0x319A, 0x3580, 0x3967, 0x3952, 0x3D3E, 0x412C, 0x451C, 0x490D, 0x4900, 0x4CF3, 0x50E8, 0x54DE, 0x58D4, 0x5CCB, 0x60C3, 0x64BB, 0x68B4, 0x68AE, 0x6CA8, 0x70A2, 0x749D, 0x7898, 0x7C93, 0x808F, 0x848A, 0x8886, 0x8C83, 0x907F, 0x947C, 0x9878, 0x9C75, 0xA073, 0xA470, 0xA86D, },
{0x2ECF, 0x2EA6, 0x2E7D, 0x2E55, 0x2E30, 0x320C, 0x31EB, 0x35CC, 0x35AF, 0x3995, 0x397D, 0x3D67, 0x4154, 0x4541, 0x4531, 0x4922, 0x4D14, 0x5107, 0x54FB, 0x54F0, 0x58E6, 0x5CDD, 0x60D4, 0x64CC, 0x68C4, 0x6CBD, 0x70B7, 0x74B1, 0x78AB, 0x7CA6, 0x7CA1, 0x809C, 0x8497, 0x8893, 0x8C8F, 0x908B, 0x9487, 0x9884, 0x9C81, 0xA07E, 0xA47B, 0xA878, },
{0x32CF, 0x32A9, 0x3284, 0x325F, 0x323C, 0x361B, 0x35FB, 0x35DD, 0x39C2, 0x3DA9, 0x3D91, 0x417B, 0x4167, 0x4555, 0x4944, 0x4D35, 0x5126, 0x5119, 0x550D, 0x5902, 0x5CF7, 0x60ED, 0x64E4, 0x64DC, 0x68D4, 0x6CCD, 0x70C6, 0x74BF, 0x78B9, 0x7CB3, 0x80AE, 0x84A9, 0x88A4, 0x8C9F, 0x909B, 0x9497, 0x9493, 0x988F, 0x9C8C, 0xA088, 0xA485, 0xA882, },
{0x36CF, 0x36AC, 0x368A, 0x3668, 0x3647, 0x3627, 0x3A09, 0x39ED, 0x3DD3, 0x3DBA, 0x41A3, 0x458E, 0x457A, 0x4967, 0x4D57, 0x4D47, 0x5138, 0x552B, 0x591E, 0x5D13, 0x5D08, 0x60FE, 0x64F4, 0x68EB, 0x6CE3, 0x70DB, 0x74D4, 0x74CD, 0x78C7, 0x7CC1, 0x80BB, 0x84B6, 0x88B0, 0x8CAC, 0x90A7, 0x94A3, 0x989E, 0x9C9A, 0xA097, 0xA493, 0xA890, 0xAC8C, },
{0x3ACF, 0x3AAF, 0x3A8E, 0x3A6F, 0x3A50, 0x3A32, 0x3E16, 0x3DFB, 0x41E2, 0x41CA, 0x45B3, 0x459E, 0x498B, 0x4D78, 0x4D67, 0x5158, 0x5549, 0x593B, 0x592E, 0x5D23, 0x6117, 0x650D, 0x6903, 0x68FA, 0x6CF2, 0x70E9, 0x74E2, 0x78DB, 0x7CD4, 0x80CE, 0x84C8, 0x88C2, 0x88BD, 0x8CB7, 0x90B3, 0x94AE, 0x98AA, 0x9CA5, 0xA0A1, 0xA49D, 0xA89A, 0xAC96, },
{0x3ECF, 0x3EB1, 0x3E93, 0x3E75, 0x3E58, 0x3E3C, 0x4221, 0x4207, 0x45EF, 0x45D8, 0x49C2, 0x49AD, 0x4D9A, 0x4D88, 0x5177, 0x5567, 0x5559, 0x594B, 0x5D3E, 0x6132, 0x6526, 0x651C, 0x6912, 0x6D08, 0x7100, 0x74F7, 0x78EF, 0x78E8, 0x7CE1, 0x80DA, 0x84D4, 0x88CE, 0x8CC8, 0x90C3, 0x94BE, 0x98B9, 0x9CB4, 0x9CB0, 0xA0AC, 0xA4A8, 0xA8A4, 0xACA0, },
{0x42CF, 0x42B3, 0x4296, 0x427B, 0x425F, 0x4245, 0x462B, 0x4612, 0x45FB, 0x49E5, 0x49CF, 0x4DBB, 0x51A9, 0x5197, 0x5586, 0x5576, 0x5967, 0x5D5A, 0x614D, 0x6140, 0x6535, 0x692A, 0x6D20, 0x7116, 0x710D, 0x7504, 0x78FC, 0x7CF5, 0x80ED, 0x84E7, 0x88E0, 0x88DA, 0x8CD4, 0x90CE, 0x94C9, 0x98C4, 0x9CBF, 0xA0BB, 0xA4B6, 0xA8B2, 0xACAE, 0xB0AA, },
{0x46CF, 0x46B5, 0x469A, 0x467F, 0x4666, 0x464C, 0x4A34, 0x4A1C, 0x4A06, 0x4DF0, 0x4DDC, 0x51C8, 0x51B6, 0x55A4, 0x5994, 0x5984, 0x5D75, 0x6167, 0x615A, 0x654E, 0x6942, 0x6D37, 0x6D2D, 0x7123, 0x751A, 0x7911, 0x7D09, 0x7D01, 0x80FA, 0x84F3, 0x88EC, 0x8CE5, 0x90DF, 0x94DA, 0x98D4, 0x98CF, 0x9CCA, 0xA0C5, 0xA4C0, 0xA8BC, 0xACB8, 0xB0B4, },
{0x4ACF, 0x4AB6, 0x4A9D, 0x4A84, 0x4A6B, 0x4A53, 0x4A3C, 0x4E25, 0x4E10, 0x51FB, 0x51E7, 0x55D4, 0x55C2, 0x59B1, 0x59A1, 0x5D91, 0x6182, 0x6175, 0x6567, 0x695B, 0x694F, 0x6D44, 0x713A, 0x7530, 0x7926, 0x791E, 0x7D15, 0x810D, 0x8505, 0x88FE, 0x88F7, 0x8CF1, 0x90EA, 0x94E4, 0x98DF, 0x9CD9, 0xA0D4, 0xA4CF, 0xA8CA, 0xA8C6, 0xACC1, 0xB0BD, },
{0x4ECF, 0x4EB7, 0x4E9F, 0x4E88, 0x4E70, 0x4E5A, 0x4E43, 0x522E, 0x5219, 0x5605, 0x55F1, 0x55DF, 0x59CD, 0x5DBC, 0x5DAC, 0x619D, 0x618F, 0x6581, 0x6974, 0x6967, 0x6D5C, 0x7151, 0x7546, 0x753C, 0x7932, 0x7D29, 0x8121, 0x8519, 0x8511, 0x8909, 0x8D02, 0x90FC, 0x94F5, 0x98EF, 0x98E9, 0x9CE3, 0xA0DE, 0xA4D9, 0xA8D4, 0xACCF, 0xB0CB, 0xB4C6, },
{0x52CF, 0x52B9, 0x52A2, 0x528B, 0x5275, 0x525F, 0x524A, 0x5635, 0x5621, 0x560E, 0x59FB, 0x59E9, 0x5DD8, 0x5DC7, 0x61B8, 0x65A9, 0x659A, 0x698D, 0x6980, 0x6D73, 0x7167, 0x755C, 0x7552, 0x7948, 0x7D3E, 0x8135, 0x812C, 0x8524, 0x891C, 0x8D14, 0x910D, 0x9106, 0x9500, 0x98F9, 0x9CF3, 0xA0ED, 0xA4E8, 0xA8E3, 0xA8DE, 0xACD9, 0xB0D4, 0xB4D0, },
{0x56CF, 0x56BA, 0x56A4, 0x568E, 0x5679, 0x5664, 0x5650, 0x5A3C, 0x5A29, 0x5A16, 0x5E04, 0x5DF2, 0x61E2, 0x61D1, 0x65C2, 0x65B3, 0x69A5, 0x6D98, 0x6D8B, 0x717E, 0x7573, 0x7567, 0x795D, 0x7D53, 0x7D49, 0x8140, 0x8537, 0x892E, 0x8D26, 0x8D1F, 0x9117, 0x9510, 0x990A, 0x9D03, 0x9CFD, 0xA0F7, 0xA4F2, 0xA8EC, 0xACE7, 0xB0E2, 0xB4DD, 0xB8D8, },
{0x5ACF, 0x5ABB, 0x5AA6, 0x5A91, 0x5A7D, 0x5A69, 0x5A55, 0x5E42, 0x5E30, 0x5E1E, 0x620C, 0x61FB, 0x65EB, 0x65DB, 0x69CC, 0x69BD, 0x6DAF, 0x6DA2, 0x7195, 0x7589, 0x757D, 0x7972, 0x7D67, 0x7D5D, 0x8154, 0x854A, 0x8941, 0x8939, 0x8D31, 0x9129, 0x9522, 0x991A, 0x9914, 0x9D0D, 0xA107, 0xA501, 0xA8FB, 0xACF5, 0xACF0, 0xB0EB, 0xB4E6, 0xB8E1, },
{0x5ECF, 0x5EBC, 0x5EA8, 0x5E94, 0x5E81, 0x5E6D, 0x5E5B, 0x6248, 0x6236, 0x6225, 0x6614, 0x6603, 0x65F3, 0x69E4, 0x69D5, 0x6DC7, 0x71B9, 0x71AC, 0x759F, 0x7593, 0x7987, 0x7D7C, 0x7D72, 0x8167, 0x855E, 0x8554, 0x894B, 0x8D43, 0x913B, 0x9533, 0x952B, 0x9924, 0x9D1D, 0xA117, 0xA510, 0xA50A, 0xA904, 0xACFE, 0xB0F9, 0xB4F4, 0xB8EF, 0xBCEA, },
{0x62CF, 0x62BC, 0x62A9, 0x6296, 0x6284, 0x6271, 0x625F, 0x664D, 0x663C, 0x662B, 0x6A1B, 0x6A0B, 0x69FB, 0x6DEC, 0x6DDD, 0x71CF, 0x71C2, 0x75B5, 0x79A9, 0x799D, 0x7D91, 0x7D86, 0x817B, 0x8571, 0x8567, 0x895E, 0x8D55, 0x914D, 0x9144, 0x953C, 0x9935, 0x9D2D, 0xA126, 0xA120, 0xA519, 0xA913, 0xAD0D, 0xB107, 0xB102, 0xB4FC, 0xB8F7, 0xBCF2, },
{0x66CF, 0x66BD, 0x66AB, 0x6699, 0x6687, 0x6675, 0x6664, 0x6652, 0x6A42, 0x6A31, 0x6A21, 0x6E12, 0x6E02, 0x71F4, 0x71E6, 0x75D8, 0x75CB, 0x79BE, 0x79B1, 0x7DA6, 0x819A, 0x818F, 0x8585, 0x857B, 0x8971, 0x8D67, 0x915F, 0x9156, 0x954E, 0x9946, 0x9D3E, 0x9D37, 0xA12F, 0xA529, 0xA922, 0xAD1C, 0xAD16, 0xB110, 0xB50A, 0xB905, 0xBD00, 0xC0FA, },
{0x6ACF, 0x6ABE, 0x6AAC, 0x6A9B, 0x6A8A, 0x6A78, 0x6A68, 0x6A57, 0x6E47, 0x6E37, 0x6E27, 0x7218, 0x7209, 0x75FB, 0x75ED, 0x79E0, 0x79D3, 0x7DC6, 0x7DBA, 0x81AE, 0x81A3, 0x8598, 0x898E, 0x8984, 0x8D7A, 0x9170, 0x9167, 0x955F, 0x9957, 0x994F, 0x9D47, 0xA13F, 0xA538, 0xA931, 0xA92B, 0xAD24, 0xB11E, 0xB518, 0xB913, 0xB90D, 0xBD08, 0xC103, },
{0x6ECF, 0x6EBF, 0x6EAE, 0x6E9D, 0x6E8C, 0x6E7C, 0x6E6B, 0x6E5B, 0x724B, 0x723C, 0x722D, 0x761E, 0x7610, 0x7602, 0x79F4, 0x79E7, 0x7DDA, 0x7DCE, 0x81C2, 0x85B6, 0x85AB, 0x89A1, 0x8996, 0x8D8C, 0x9182, 0x9179, 0x9570, 0x9967, 0x995F, 0x9D57, 0xA14F, 0xA548, 0xA541, 0xA93A, 0xAD33, 0xB12D, 0xB526, 0xB520, 0xB91B, 0xBD15, 0xC110, 0xC50A, },
{0x72CF, 0x72BF, 0x72AF, 0x729F, 0x728E, 0x727F, 0x726F, 0x725F, 0x7650, 0x7641, 0x7632, 0x7A24, 0x7A16, 0x7A08, 0x7DFB, 0x7DEE, 0x81E2, 0x81D5, 0x85CA, 0x85BE, 0x89B3, 0x8DA9, 0x8D9E, 0x9194, 0x918B, 0x9581, 0x9978, 0x9970, 0x9D67, 0xA15F, 0xA558, 0xA550, 0xA949, 0xAD42, 0xB13B, 0xB135, 0xB52E, 0xB928, 0xBD23, 0xC11D, 0xC117, 0xC512, },
{0x76CF, 0x76C0, 0x76B0, 0x76A0, 0x7691, 0x7681, 0x7672, 0x7663, 0x7A54, 0x7A46, 0x7A37, 0x7E29, 0x7E1C, 0x7E0E, 0x8201, 0x81F5, 0x85E8, 0x85DC, 0x89D1, 0x89C6, 0x8DBB, 0x8DB0, 0x91A6, 0x959C, 0x9593, 0x9989, 0x9980, 0x9D78, 0xA170, 0xA567, 0xA560, 0xA958, 0xAD51, 0xAD4A, 0xB143, 0xB53D, 0xB936, 0xBD30, 0xBD2A, 0xC125, 0xC51F, 0xC91A, },
{0x7ACF, 0x7AC0, 0x7AB1, 0x7AA2, 0x7A93, 0x7A84, 0x7A75, 0x7A66, 0x7E58, 0x7E4A, 0x7E3C, 0x7E2E, 0x8221, 0x8214, 0x8607, 0x85FB, 0x89EF, 0x89E3, 0x89D8, 0x8DCD, 0x91C2, 0x91B8, 0x95AD, 0x95A4, 0x999A, 0x9D91, 0x9D88, 0xA180, 0xA577, 0xA56F, 0xA967, 0xAD60, 0xAD59, 0xB152, 0xB54B, 0xB944, 0xB93E, 0xBD38, 0xC132, 0xC52C, 0xC926, 0xC921, },
{0x7ECF, 0x7EC1, 0x7EB2, 0x7EA3, 0x7E95, 0x7E86, 0x7E78, 0x7E6A, 0x825C, 0x824E, 0x8240, 0x8233, 0x8626, 0x8619, 0x8A0D, 0x8A01, 0x89F5, 0x8DEA, 0x8DDE, 0x91D3, 0x91C9, 0x95BF, 0x99B5, 0x99AB, 0x9DA2, 0x9D98, 0xA190, 0xA587, 0xA57F, 0xA977, 0xAD6F, 0xAD67, 0xB160, 0xB559, 0xB952, 0xB94C, 0xBD45, 0xC13F, 0xC539, 0xC533, 0xC92E, 0xCD28, },
{0x82CF, 0x82C1, 0x82B3, 0x82A5, 0x8296, 0x8288, 0x827B, 0x826D, 0x825F, 0x8652, 0x8645, 0x8638, 0x8A2B, 0x8A1F, 0x8A12, 0x8E07, 0x8DFB, 0x91F0, 0x91E5, 0x95DA, 0x95CF, 0x99C5, 0x99BB, 0x9DB2, 0xA1A9, 0xA1A0, 0xA597, 0xA58E, 0xA986, 0xAD7E, 0xAD76, 0xB16F, 0xB567, 0xB560, 0xB95A, 0xBD53, 0xC14D, 0xC146, 0xC540, 0xC93A, 0xCD35, 0xD12F, },
{0x86CF, 0x86C2, 0x86B4, 0x86A6, 0x8698, 0x868B, 0x867D, 0x8670, 0x8662, 0x8A55, 0x8A49, 0x8A3C, 0x8E30, 0x8E23, 0x8E18, 0x920C, 0x9201, 0x95F5, 0x95EB, 0x99E0, 0x99D6, 0x9DCC, 0x9DC2, 0xA1B8, 0xA1AF, 0xA5A6, 0xA99E, 0xA995, 0xAD8D, 0xAD85, 0xB17D, 0xB576, 0xB56F, 0xB967, 0xBD61, 0xC15A, 0xC154, 0xC54D, 0xC947, 0xCD41, 0xCD3C, 0xD136, },
{0x8ACF, 0x8AC2, 0x8AB5, 0x8AA7, 0x8A9A, 0x8A8D, 0x8A7F, 0x8A72, 0x8A66, 0x8E59, 0x8E4C, 0x8E40, 0x9234, 0x9228, 0x921C, 0x9611, 0x9606, 0x99FB, 0x99F0, 0x99E6, 0x9DDC, 0x9DD2, 0xA1C8, 0xA5BF, 0xA5B6, 0xA9AD, 0xA9A4, 0xAD9C, 0xB194, 0xB18C, 0xB584, 0xB97D, 0xB975, 0xBD6E, 0xC167, 0xC161, 0xC55A, 0xC954, 0xC94E, 0xCD48, 0xD142, 0xD53D, },
{0x8ECF, 0x8EC2, 0x8EB5, 0x8EA8, 0x8E9B, 0x8E8E, 0x8E82, 0x8E75, 0x8E68, 0x925C, 0x9250, 0x9244, 0x9638, 0x962C, 0x9621, 0x9A16, 0x9A0B, 0x9A00, 0x9DF6, 0x9DEC, 0xA1E2, 0xA1D8, 0xA5CE, 0xA5C5, 0xA9BC, 0xADB3, 0xADAB, 0xB1A2, 0xB19A, 0xB592, 0xB98B, 0xB983, 0xBD7C, 0xC175, 0xC16E, 0xC567, 0xC961, 0xC95B, 0xCD55, 0xD14F, 0xD549, 0xD543, },
{0x92CF, 0x92C3, 0x92B6, 0x92A9, 0x929D, 0x9290, 0x9284, 0x9277, 0x926B, 0x965F, 0x9653, 0x9648, 0x963C, 0x9A31, 0x9A25, 0x9E1B, 0x9E10, 0x9E05, 0xA1FB, 0xA1F1, 0xA5E7, 0xA5DD, 0xA9D4, 0xA9CB, 0xADC2, 0xADB9, 0xB1B1, 0xB5A9, 0xB5A1, 0xB999, 0xB991, 0xBD8A, 0xC182, 0xC17B, 0xC575, 0xC96E, 0xC967, 0xCD61, 0xD15B, 0xD555, 0xD54F, 0xD94A, },
{0x96CF, 0x96C3, 0x96B7, 0x96AA, 0x969E, 0x9692, 0x9686, 0x967A, 0x966E, 0x9A62, 0x9A57, 0x9A4B, 0x9A40, 0x9E35, 0x9E2A, 0x9E1F, 0xA214, 0xA20A, 0xA600, 0xA5F6, 0xA9EC, 0xA9E3, 0xADDA, 0xADD1, 0xB1C8, 0xB1BF, 0xB5B7, 0xB5AF, 0xB9A7, 0xBD9F, 0xBD97, 0xC190, 0xC189, 0xC582, 0xC97B, 0xC974, 0xCD6E, 0xD167, 0xD561, 0xD55B, 0xD956, 0xDD50, },
{0x9ACF, 0x9AC3, 0x9AB7, 0x9AAB, 0x9A9F, 0x9A94, 0x9A88, 0x9A7C, 0x9A70, 0x9E65, 0x9E5A, 0x9E4E, 0x9E43, 0xA238, 0xA22E, 0xA223, 0xA619, 0xA60F, 0xAA05, 0xA9FB, 0xA9F1, 0xADE8, 0xADDF, 0xB1D6, 0xB1CD, 0xB5C5, 0xB9BC, 0xB9B4, 0xBDAC, 0xBDA5, 0xC19D, 0xC596, 0xC58F, 0xC988, 0xC981, 0xCD7A, 0xD174, 0xD56E, 0xD567, 0xD962, 0xDD5C, 0xDD56, },
{0x9ECF, 0x9EC4, 0x9EB8, 0x9EAC, 0x9EA1, 0x9E95, 0x9E8A, 0x9E7E, 0x9E73, 0xA268, 0xA25C, 0xA251, 0xA247, 0xA63C, 0xA632, 0xA627, 0xAA1D, 0xAA13, 0xAA09, 0xAE00, 0xADF6, 0xB1ED, 0xB1E4, 0xB5DB, 0xB5D3, 0xB9CA, 0xB9C2, 0xBDBA, 0xC1B2, 0xC1AA, 0xC5A3, 0xC59C, 0xC995, 0xCD8E, 0xCD87, 0xD180, 0xD57A, 0xD574, 0xD96D, 0xDD67, 0xDD62, 0xE15C, },
{0xA2CF, 0xA2C4, 0xA2B9, 0xA2AD, 0xA2A2, 0xA296, 0xA28B, 0xA280, 0xA275, 0xA66A, 0xA65F, 0xA654, 0xA64A, 0xAA3F, 0xAA35, 0xAA2B, 0xAE21, 0xAE17, 0xAE0E, 0xB204, 0xB1FB, 0xB5F2, 0xB5E9, 0xB9E0, 0xB9D8, 0xBDCF, 0xBDC7, 0xC1BF, 0xC1B8, 0xC5B0, 0xC9A9, 0xC9A1, 0xCD9A, 0xCD93, 0xD18D, 0xD586, 0xD580, 0xD979, 0xDD73, 0xDD6D, 0xE167, 0xE562, },
{0xA6CF, 0xA6C4, 0xA6B9, 0xA6AE, 0xA6A3, 0xA698, 0xA68D, 0xA682, 0xA677, 0xA66C, 0xAA62, 0xAA57, 0xAA4D, 0xAE43, 0xAE39, 0xAE2F, 0xB225, 0xB21B, 0xB212, 0xB609, 0xB5FF, 0xB9F7, 0xB9EE, 0xBDE5, 0xBDDD, 0xC1D5, 0xC1CC, 0xC5C5, 0xC5BD, 0xC9B5, 0xC9AE, 0xCDA7, 0xD1A0, 0xD199, 0xD592, 0xD58C, 0xD985, 0xDD7F, 0xDD79, 0xE173, 0xE56D, 0xE567, },
};
#endif
// 此处通过 uint32_t 返回数据由于数据丢失会产生奇特的效果
static uint16_t _cledMatrixAngle(float x, float y, float cx, float cy)
{
    double angle    = (atan2(x - cx, y - cy)) * 180 / 3.14159265359;
    double distance = sqrt(pow(cx - x, 2) + pow(cy - y, 2));

    struct cledMatrixPixelLimit piont;

    piont.angle = (uint16_t)(angle*8.0f);     // 90*8 = 720:10bit[1024]
    piont.radius = (uint16_t)(distance); // 21*2 = 42: 6bit [64]

    return piont.pixel;
}
/*************************************************************************************************
* 为节省空间占用,仅计算 0-90°范围,其它角度根据象限间的关系重新计算
* 为节保留 精度并加快运算速度,将处理后的结果保存为整型，精度为 1/64
**************************************************************************************************/
void cledMatrixAngleLimit(const uint16_t cols, const uint16_t rows)
{
    float cx = 0;//(cols - 1) * 0.5;
    float cy = 0;//(rows - 1) * 0.5;
    struct cledMatrixPixelLimit matrix[128][128];
    for (uint32_t col_id = 0; col_id < cols; col_id++)
    {
        for (uint32_t row_id = 0; row_id < rows; row_id++)
        {
            matrix[col_id][row_id].pixel = _cledMatrixAngle(col_id, row_id, cx, cy);
        }
    }
    //printf("const uint16_t RotateMatrix[%d][%d] = {\r\n", MATRIX_SIZE, MATRIX_SIZE);
    //printf("const uint16_t RotateMatrixAngle[MATRIX_SIZE][MATRIX_SIZE] = {\r\n");
    //printf("const uint32_t RotateMatrixAngle[%d][%d] = {\r\n", cols, rows);
    printf("static const uint16_t RotateMatrixAngle[MATRIX_ANGLE_SIZE][MATRIX_ANGLE_SIZE] = {\r\n");
    for(int y=0; y<rows; y++)
    {
        printf("{");
        for(int x=0; x<cols; x++)
        {
            //printf("%4d, ",  (int)matrix[y][x].angle);
            printf("0x%04X, ",  matrix[y][x].pixel);
        }
        printf("},\r\n");
    }
    printf("};\r\n");
#if 0
    printf("static const uint16_t angle[MATRIX_ANGLE_SIZE][MATRIX_ANGLE_SIZE] = {\r\n");
    for(int y=0; y<rows; y++)
    {
        printf("{");
        for(int x=0; x<cols; x++)
        {
            //printf("%4d, ",  (int)matrix[y][x].angle);
            printf("%3d, ",  matrix[y][x].angle);
        }
        printf("},\r\n");
    }
    printf("};\r\n");
    printf("static const uint16_t radius[MATRIX_ANGLE_SIZE][MATRIX_ANGLE_SIZE] = {\r\n");
    for(int y=0; y<rows; y++)
    {
        printf("{");
        for(int x=0; x<cols; x++)
        {
            //printf("%4d, ",  (int)matrix[y][x].angle);
            printf("%3d, ",  matrix[y][x].radius);
        }
        printf("},\r\n");
    }
    printf("};\r\n");
#endif
    fflush(stdout);
}
void cledMatrixAngleLimit2(void)
{
    cledMatrixAngleLimit(MATRIX_ANGLE_SIZE, MATRIX_ANGLE_SIZE);
}
uint32_t cledMatrixAngleLimitGet(const int16_t x, const int16_t y)
{
    struct cledMatrixPixelLimit Piont = {0};
    struct cledMatrixPixel piont = {0};
    if((x>=MATRIX_ANGLE_SIZE) || (x<=-MATRIX_ANGLE_SIZE)) return 0;
    if((y>=MATRIX_ANGLE_SIZE) || (y<=-MATRIX_ANGLE_SIZE)) return 0;
    if((x>=0) && (y>=0)) // 第一象限
    {
        Piont.pixel = RotateMatrixAngle[y][x];
        piont.angle = Piont.angle;
        piont.radius = Piont.radius;
    }
    if((x<0) && (y>=0)) // 第二象限
    {
        Piont.pixel = RotateMatrixAngle[y][-x];
        piont.angle = Piont.angle;
        piont.radius = Piont.radius;
        piont.angle = (uint32_t)(180*8) - piont.angle;
    }
    if((x<0) && (y<0)) // 第三象限
    {
        Piont.pixel = RotateMatrixAngle[-y][-x];
        piont.angle = Piont.angle;
        piont.radius = Piont.radius;
        piont.angle = (uint32_t)(180*8) + piont.angle;
    }
    if((x>=0) && (y<0)) // 第四象限
    {
        Piont.pixel = RotateMatrixAngle[-y][x];
        piont.angle = Piont.angle;
        piont.radius = Piont.radius;
        piont.angle = (uint32_t)(360*8) - piont.angle;
    }
    return piont.pixel;
}
